import { POST } from '@/libs/index';
import { UserInfo } from '@/store/modules/user.module';
export type GetCodeResponse = string;

export const getCode = (phone: string) => {
  return POST<GetCodeResponse>({
    url: '/auth/getCode',
    data: {
      phone
    }
  });
};

interface LoginDto {
  phone: string;
  code: string;
  token: string;
  avatarUrl: string;
  language: 'zh_CN';
  nickName: string;
  openId: string;
}

export interface LoginResponseData {
  token: string;
  userInfo: UserInfo;
}

export const login = (loginDto: LoginDto) => {
  return POST<LoginResponseData>({
    url: '/auth/login',
    data: loginDto
  });
};
